package com.lizongbo.seotijian.rules.internetaccount;

import com.lizongbo.seotijian.rules.internetaccount.handlers.QQWeiboAccountCheckHandler;
import com.lizongbo.seotijian.rules.internetaccount.handlers.TwitterAccountCheckHandler;

public class InternetAccountCheckClient {
	private static java.util.Map<String, AccountCheckHandler> map = new java.util.HashMap<String, AccountCheckHandler>();
	static {
		addAccountCheckHandler(new TwitterAccountCheckHandler());
		addAccountCheckHandler(new QQWeiboAccountCheckHandler());
		addAccountCheckHandler(new TwitterAccountCheckHandler());
	}

	private static void addAccountCheckHandler(AccountCheckHandler a) {
		map.put(a.getSiteDomain(), a);
	}

	/**
	 * 从域名中截取出可以做用户名的字符串
	 * 
	 * @param domain
	 * @return
	 */
	public static String getUserName(String domain) {
		String userName = domain;
		if (domain.indexOf(".") > 0) {
			userName = domain.substring(0, domain.indexOf("."));
		}
		return userName;
	}

	public static void main(String[] args) {
		String username = "lizongbo";
		for (java.util.Map.Entry<String, AccountCheckHandler> e : map
				.entrySet()) {
			System.out.println(e.getValue().isExistAccount(username));
		}

	}

}
